package com.health.home.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.health.common.core.po.DepartmentPo;
import com.health.common.core.po.DiseasePo;
import com.health.home.domain.Department;
import com.health.home.domain.vo.DiseaseVo;
import com.health.home.service.DepartmentService;
import com.health.home.service.DiseaseService;
import com.health.home.util.PageResult;
import com.health.home.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xpz
 * @date 2024/12/11 12:29
 */

@RestController
@RequestMapping("/disease")
public class DiseaseController {

    @Autowired
    private DiseaseService diseaseService;

    @Autowired
    private DepartmentService departmentService;

    /**
     * 查询科室关联病症信息 对接患者前端
     * @param
     * @return
     */
     @GetMapping("/diseaseList")
     public Result<List<DiseasePo>> diseaseList(){
         List<DiseasePo> list = diseaseService.diseaseList();
         return  Result.success(list);

     }

    /**
     * 单个查询病症信息 对接后台管理前端
     */
     @PostMapping("/diseaseLists")
     public Result<PageResult<DiseasePo>> diseaseLists(@ModelAttribute DiseaseVo diseaseVo){
         PageHelper.startPage(diseaseVo.getPageNum(), diseaseVo.getPageSize());
         List<DiseasePo> list = diseaseService.diseaseLists(diseaseVo);
         PageInfo<DiseasePo> info = new PageInfo<>(list);
         return PageResult.toResult(info.getTotal(),list);
     }

    /**
     * 新增病症信息 对接后台管理前端
     * @return
     */
    @PostMapping("/diseaseAdd")
     public Result diseaseAdd(@ModelAttribute DiseasePo diseasePo){
        return diseaseService.diseaseAdd(diseasePo);
    }

    /**
     * 编辑病症信息 对接后台管理前端
     * @return
     */
    @PostMapping("/diseaseUpdate")
    public Result diseaseUpdate(@ModelAttribute DiseasePo diseasePo){
        return diseaseService.diseaseUpdate(diseasePo);
    }
    /**
     * 删除病症信息 对接后台管理前端
     */
     @GetMapping("/diseaseDel")
     public Result diseaseDel(@RequestParam("id") Integer id){
           diseaseService.removeById(id);
            return Result.success();
     }


    /**
     * 查询所有科室信息 对接后台管理前端
     */
     @PostMapping("/departmentList")
     public List<DepartmentPo> departmentList(@ModelAttribute Department department){
         return  departmentService.lists(department);
     }

    /**
     * 新增科室信息 对接后台管理前端
     */
     @PostMapping("departmentAdd")
     public Result departmentAdd(@ModelAttribute  DepartmentPo departmentPo){
            departmentService.save(departmentPo);
            return Result.success();
     }

    /**
     * 编辑科室信息 对接后台管理前端
     */
    @PostMapping("departmentUpdate")
    public Result departmentUpdate(@ModelAttribute  DepartmentPo departmentPo){
        departmentService.updateById(departmentPo);
        return Result.success();
    }

    /**
     * 删除科室信息 对接后台管理前端
     */
    @GetMapping("departmentDel")
    public Result departmentDel(@RequestParam("id") Integer id){
        departmentService.removeById(id);
        return Result.success();
    }

}
